import store from '@/store/index.js';
import helper from 'common/js/helper.js'

var baseui = {
	internalData: function() {
		this.userListAll();
		this.organizeListAll();
		this.roleListAll();
		this.positionListAll();
		this.dictionaryData();
		this.flowEngineListAll();
		this.userProvider();
	},
	dictionaryData: function() {
		helper.ajax({
			url: "/api/System/DictionaryData/BindDictionary",
			success: function(res) {
				if (res.data.code == '200') {
					const _data = res.data.data;
					store.dispatch('collection/invokeDictionaryData', _data)
				}
			}
		});
	},
	organizeListAll: function() {
		helper.ajax({
			url: "/api/Permission/Organize/ListAll",
			success: function(res) {
				if (res.data.code == '200') {
					let _data = {};
					const organizeList = res.data.data;
					for (let i = 0; i < organizeList.length; i++) {
						_data[organizeList[i].F_Id] = {
							'F_EnCode': organizeList[i].F_EnCode,
							'F_FullName': organizeList[i].F_FullName,
							'F_ParentId': organizeList[i].F_ParentId,
							'F_Category': organizeList[i].F_Category
						};
					};
					store.dispatch('collection/invokeOrganizeList', _data)
				}
			}
		});
	},
	positionListAll: function() {
		helper.ajax({
			url: "/api/Permission/Position/ListAll",
			success: function(res) {
				if (res.data.code == '200') {
					let _data = {};
					const positionList = res.data.data;
					for (let i = 0; i < positionList.length; i++) {
						_data[positionList[i].F_Id] = {
							'F_EnCode': positionList[i].F_EnCode,
							'F_FullName': positionList[i].F_FullName,
							'F_OrganizeId': positionList[i].F_OrganizeId
						};
					};
					store.dispatch('collection/invokePositionList', _data)
				}
			}
		});
	},
	roleListAll: function() {
		helper.ajax({
			url: "/api/Permission/Role/ListAll",
			success: function(res) {
				if (res.data.code == '200') {
					let _data = {};
					const roleList = res.data.data;
					for (let i = 0; i < roleList.length; i++) {
						_data[roleList[i].F_Id] = {
							'F_EnCode': roleList[i].F_EnCode,
							'F_FullName': roleList[i].F_FullName
						};
					};
					store.dispatch('collection/invokeRoleList', _data)
				}
			}
		});
	},
	userListAll: function() {
		helper.ajax({
			url: "/api/Permission/User/ListAll",
			success: function(res) {
				if (res.data.code == '200') {
					var _data = [];
					const userList = res.data.data;
					for (let i = 0; i < userList.length; i++) {
						_data[userList[i].F_Id] = {
							'F_Account': userList[i].F_Account,
							'F_RealName': userList[i].F_RealName,
							'F_Name': userList[i].F_RealName + "/" + userList[i].F_Account,
							'F_Gender': userList[i].F_Gender,
							'F_HeadIcon': userList[i].F_HeadIcon.replace(".", "@"),
							'F_OrganizeId': userList[i].F_OrganizeId,
							'F_QuickQuery': userList[i].F_QuickQuery
						};
					};
					store.dispatch('collection/invokeUserList', _data)
				}
			},
		});
	},
	userProvider: function() {
		helper.ajax({
			url: '/api/Home/APPData',
			method: 'GET',
			data: '',
			success: res => {
				const _data = res.data.data;
				store.dispatch('collection/invokeUserProviderList', _data)
			},
		});
	},
	flowEngineListAll: function() {
		helper.ajax({
			url: "/api/WorkFlow/FlowEngine/ListAll",
			success: function(res) {
				if (res.data.code == '200') {
					let _data = [];
					const flowEngineList = res.data.data;
					for (let i = 0; i < flowEngineList.length; i++) {
						_data.push({
							'F_Id': flowEngineList[i].F_Id,
							'F_Category': flowEngineList[i].F_Category,
							'F_FullName': flowEngineList[i].F_FullName,
							'F_IconBackground': flowEngineList[i].F_IconBackground,
							'F_Icon': flowEngineList[i].F_Icon,
							'F_EnCode': flowEngineList[i].F_EnCode,
							'F_Iscom': false
						});
					};
					store.dispatch('collection/invokeFlowEngineList', _data)
				}
			}
		});
	},
}
export default baseui
